package com.aitesting.testcase;

import com.aitesting.domain.IStep;
import com.aitesting.domain.TStep;
import java.util.Map;

/**
 * 填充请求数据
 */
public class StepWithOptionArgs implements IStep {

    private final TStep step;

    public StepWithOptionArgs(TStep step) {
        this.step = step;
    }

    /**
     * 填充参数
     * @param params 请求参数
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs with_params(Map<String, String> params){
        this.step.getRequest().getParams().putAll(params);
        return this;
    }

    /**
     * 填充请求头
     * @param headers 请求头
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs with_headers(Map<String, String> headers){
        this.step.getRequest().getHeaders().putAll(headers);
        return this;
    }

    /**
     * 填充cookie
     * @param cookies 请求cookie
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs with_cookies(Map<String, String> cookies){
        this.step.getRequest().getCookies().putAll(cookies);
        return this;
    }

    /**
     * 填充填充体
     * @param data 请求体
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs with_data(Map<String, Object> data){
        this.step.getRequest().getData().putAll(data);
        return this;
    }

    /**
     * 填充超时时间
     * @param timeout 超时时间
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs set_timeout(float timeout){
        this.step.getRequest().setTimeout(timeout);
        return this;
    }

    /**
     * 是否允许重定向
     * @param allow_Redirects 是否允许重定向
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs set_allow_redirects(boolean allow_Redirects){
        this.step.getRequest().setAllow_redirects(allow_Redirects);
        return this;
    }

    /**
     * 填充上传的文件
     * @param upload 上传的文件
     * @return RequestWithOptionArgs对象
     */
    public StepWithOptionArgs with_upload(Map<String, Object> upload){
        this.step.getRequest().getUpload().putAll(upload);
        return this;
    }

    /**
     * 添加断言信息
     * @return RequestWithValidation对象
     */
    public StepWithValidation validate(){
        return new StepWithValidation(step);
    }

    /**
     * 提取接口返回参数
     * @return StepRequestExtraction对象
     */
    public StepRequestExtraction extract(){
        return new StepRequestExtraction(step);
    }

    @Override
    public TStep perform() {
        return this.step;
    }
}
